package cn.edu.zafu.bigdata.x.yaojy;

public class AgeChecker {
    public static void checkAge(int age) throws InvalidAgeException{
        if (age < 18){
            throw new InvalidAgeException("年龄不能小于18岁！");
        }
    }

    public static void main(String[] args) {
        int age = 16;
        try{
            checkAge(age);
            System.out.println("年龄合法");
        } catch (InvalidAgeException e){
            System.out.println("错误信息：" + e.getMessage());
        }

        age = 18;
        try{
            checkAge(age);
            System.out.println("年龄合法");
        } catch (InvalidAgeException e){
            System.out.println("错误信息：" + e.getMessage());
        }
    }
}
